package cn.zhouyafeng;

import java.util.Calendar;

public class WatherMain {

    public int all = 2000; // 一天喝水量
    public int once = all / 13; // 一次喝水量

    public int count = 0 ; // 喝水几次
    public int done = 0 ; // 已喝水

    public static void main(String[] args) {
        WatherMain wa = new WatherMain();
        System.out.println(wa.alert());
    }

    public String getNow(){
        resetCount();

        StringBuilder sb = getStringBuilder();
        sb.append(String.format("注意休息，切勿久坐, 医生建议 \n一天喝水量是 2000ml")).append("");

        return sb.toString();
    }

    public String alert(){
        resetCount();

        StringBuilder sb = getStringBuilder();
        sb.append(String.format("现在需要喝水 %sml", once)).append("");

        return sb.toString();
    }

    private StringBuilder getStringBuilder() {
        Calendar instance = Calendar.getInstance();
        int hour = instance.get(Calendar.HOUR_OF_DAY);
        int min = instance.get(Calendar.MINUTE);

        StringBuilder sb = new StringBuilder();

        sb.append(String.format("现在时间 %s:%s", hour, min)).append("\n");
        sb.append(String.format("您已经喝水 %s次，%sml, \n剩余量 %sml", count, done, all - done)).append("\n");
        return sb;
    }

    public void resetCount() {
        Calendar instance = Calendar.getInstance();
        int hour = instance.get(Calendar.HOUR_OF_DAY);
        int min = instance.get(Calendar.MINUTE);
        if (min >= 30) {
            hour +=1;
        }
        count = hour - 9;
        done = once * count;
    }
}
